﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace c2
{
    internal class Program
    {



        static void Main(string[] args)
        {
            clock c = new clock();
            clk d = new clk();
           c.Tick += d.tick;
            c.Alarm += d.alrm;
            c.start();
        }
        class clock
        {
            int time;//初始时间
            public clock()
            {
                time = 0;//定义为0秒开始

            }
            public delegate void myclock();
            public event myclock Tick;
            public event myclock Alarm;
           
            public void start()
            {
                while (true) {
                    time = time + 1;
                    if (Tick != null)
                        Tick();
                    if (Alarm != null &&time==5)//在第5秒时触发Alarm事件
                        Alarm();
                    if (time == 60)//60秒一个轮回
                        time = 0;
                    Thread.Sleep(1000);
                }
            }
        }
        class clk
        {
          
            public void tick()
            {

                Console.WriteLine("Tick!");
            }
            public void alrm()
            {
                    Console.WriteLine("Alarm!");
                
                }
            
            
        }

    }
}
